package model.components.links.factory;

import model.components.links.link.PhysicalLink;

public class PhysicalLinksFactory extends LinksFactory
{
	public static final int MIN_BANDWIDTH =  50;
	public static final int MAX_BANDWIDTH = 100;
	
	public static final int MIN_DISTANCE =   1;
	public static final int MAX_DISTANCE = 100;
	
	private int minDistance;
	public int getMinDistance(){ return minDistance; }
	public void setMinDistance( int minDistance ){ this.minDistance = minDistance; }
	
	private int maxDistance;
	public int getMaxDistance(){ return maxDistance; }
	public void setMaxDistance( int maxDistance ){ this.maxDistance = maxDistance; }

	public PhysicalLinksFactory( String networkName )
	{
		super( networkName, MIN_BANDWIDTH, MAX_BANDWIDTH );
		
		this.setMinDistance( MIN_DISTANCE );
		this.setMaxDistance( MAX_DISTANCE );
	}
	
	public PhysicalLinksFactory( String networkName, int minBandwidth, int maxBandwidth, int minDistance, int maxDistance )
	{
		super( networkName, minBandwidth, maxBandwidth );
		
		this.setMinDistance( minDistance );
		this.setMaxDistance( maxDistance );
	}
	
	@Override
	public PhysicalLink create()
	{
		PhysicalLink physicalLink = new PhysicalLink( this.getNetworkName(), this.getLinkCount(), this.randomBandwidth(), this.randomDistance() );
		this.setLinkCount( this.getLinkCount() + 1 );
		
		return physicalLink;
	}
	private int randomDistance()
	{
		return this.getMinDistance() + (int)( Math.random() * ( this.getMaxDistance() - this.getMinDistance() + 1 ) );
	}
	
}
